# This file is named BUILD.bazel instead of the more typical BUILD, so that on
# OSX it won't conflict with a build artifacts directory named "build".

load("//tools/skylark:py.bzl", "py_library")
load("//tools/install:install.bzl", "install", "install_test")
load("//tools/lint:lint.bzl", "add_lint_tests")

package(
    default_visibility = ["//visibility:public"],
)

exports_files([
    "CPPLINT.cfg",
    ".bazelproject",
    ".clang-format",
    ".drake-find_resource-sentinel",
    "package.xml",
])

# Drake's top-level module; all drake_py_stuff rules add this to deps.
# (We use py_library here because drake_py_library would be circular.)
# This file should NOT be installed (see commits in __init__.py).
py_library(
    name = "module_py",
    srcs = ["__init__.py"],
)

# Expose shared library for (a) installed binaries, (b) Drake Python bindings,
# and (c) downstream C++ libraries which will also provide Python bindings.
alias(
    name = "drake_shared_library",
    actual = "//tools/install/libdrake:drake_shared_library",
    visibility = ["//visibility:public"],
)

# A manually-curated collection of most model files in Drake, so that we can
# easily provide access to them for tools like //tools:model_visualizer.
filegroup(
    name = "all_models",
    data = [
        "//bindings/pydrake/multibody:models",
        "//examples/acrobot:models",
        "//examples/atlas:models",
        "//examples/hardware_sim:demo_data",
        "//examples/hydroelastic/ball_plate:floor_files",
        "//examples/hydroelastic/ball_plate:plate_files",
        "//examples/hydroelastic/python_ball_paddle:ball_paddle_files",
        "//examples/hydroelastic/python_nonconvex_mesh:models",
        "//examples/hydroelastic/spatula_slip_control:models",
        "//examples/kuka_iiwa_arm/models",
        "//examples/manipulation_station:models",
        "//examples/multibody/cart_pole:models",
        "//examples/multibody/four_bar:models",
        "//examples/pendulum:models",
        "//examples/planar_gripper:models",
        "//examples/pr2:models",
        "//examples/quadrotor:models",
        "//examples/scene_graph:models",
        "//examples/simple_gripper:simple_gripper_models",
        "//manipulation/models/allegro_hand_description:models",
        "//manipulation/models/franka_description:models",
        "//manipulation/models/iiwa_description:models",
        "//manipulation/models/jaco_description:models",
        "//manipulation/models/realsense2_description:models",
        "//manipulation/models/tri_homecart:models",
        "//manipulation/models/ur3e:models",
        "//manipulation/models/wsg_50_description:models",
        "//manipulation/models/ycb:models",
        "//multibody/benchmarks/acrobot:models",
    ],
    visibility = ["//:__subpackages__"],
)

# A manually-curated collection of some test model files in Drake, for use by
# //tools:model_visualizer_private.
filegroup(
    name = "some_test_models",
    testonly = True,
    data = [
        # It's okay to add more items to this list, as needed.
        "//geometry/render:test_models",
        "//manipulation/util:test_models",
        "//manipulation/util:test_directives",
        "//multibody/parsing:test_models",
        "//geometry:test_obj_files",
        "//geometry:test_stl_files",
        "//geometry:test_vtk_files",
        "//geometry:environment_maps",
        "//geometry/render_gltf_client:merge_resources",
        "//geometry/render_gltf_client:gltf_client_test_models",
    ],
    visibility = ["//tools:__pkg__"],
)

# To create a manifest of all installed files for use by drake_bazel_installed,
# we declare an install target that contains almost everything -- but it can't
# contain the bazel logic that is generated based on the manifest, so we'll add
# that in below in the final :install target.
install(
    name = "all_install_targets_except_bazel",
    data = ["package.xml"],
    docs = ["LICENSE.TXT"],
    visibility = ["//tools/install/bazel:__pkg__"],
    deps = [
        "//bindings/pydrake:install",
        "//common:install",
        "//examples:install",
        "//geometry:install",
        "//lcmtypes:install",
        "//manipulation/models:install_data",
        "//multibody/parsing:install",
        "//setup:install",
        "//tools/install/libdrake:install",
        "//tools/workspace:install_external_packages",
        "//tutorials:install",
    ],
)

_INSTALL_TEST_COMMANDS = "install_test_commands"

install(
    name = "install",
    install_tests_script = _INSTALL_TEST_COMMANDS,
    deps = [
        ":all_install_targets_except_bazel",
        "//tools/install/bazel:install",
    ],
)

install_test(
    name = "install_test",
    args = ["--install_tests_filename=$(location :{})".format(
        _INSTALL_TEST_COMMANDS,
    )],
    data = [
        ":install",
        _INSTALL_TEST_COMMANDS,
    ],
    tags = [
        # Running acceptance tests under coverage (kcov) can fail for presently
        # unknown reasons when it comes to drake_visualizer, so skip them.
        "no_kcov",
        # Running acceptance tests under Valgrind tools is extremely slow and
        # of limited value, so skip them.
        "no_valgrind_tools",
    ],
)

add_lint_tests(
    bazel_lint_extra_srcs = glob(
        [
            "cmake/external/workspace/**/*.bazel.in",
            "cmake/external/workspace/**/*.bzl",
        ],
        allow_empty = False,
    ),
)
